package org.bsplus.client;

import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.AnchorData;
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.user.client.Window;

import com.google.gwt.user.client.ui.RootPanel;
import net.customware.gwt.presenter.client.DefaultEventBus;
import net.customware.gwt.presenter.client.EventBus;
import org.bsplus.client.gin.BSPlusGinjector;
import org.bsplus.client.mvp.MainPresenter;
import org.bsplus.client.mvp.MainView;

public class MainEntryPoint implements EntryPoint
{
    private final BSPlusGinjector injector = GWT.create(BSPlusGinjector.class);

    /** Creates a new instance of MainEntryPoint */
    public MainEntryPoint()
    {
        GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler()
        {
            @Override
            public void onUncaughtException(Throwable e)
            {
                Window.alert("Unexpected Error: " + e.getMessage());
                e.printStackTrace();
            }
        });
    }

    @Override
    public void onModuleLoad()
    {
        MainPresenter mainPresenter = injector.getMainPresenter();
        mainPresenter.bind();

        Viewport vp = new Viewport();
        vp.setLayout(new AnchorLayout());
        vp.add(mainPresenter.getDisplay().asWidget(), new AnchorData("100% 100%"));
        RootPanel.get().add(vp);
    }
}

